package com.hard;

/**
 * Created by Lxk on 2020/2/22.
 */
public class Solution335 {

    public boolean isSelfCrossing(int[] x) {
        int sumN = 0, sumS = 0, sumW = 0, sumE = 0;
        for (int i = 0; i < x.length; i++) {
            if (i % 4 == 0) {
                sumN += x[i];
            } else if (i % 4 == 1) {
                sumW += x[i];
            } else if (i % 4 == 2) {
                sumS += x[i];
            } else {
                sumE += x[i];
            }
            if (i >= 3 && sumN >= sumS && sumW <= sumE) {
                return true;
            }
            if (i >= 3 && sumN >= sumS && sumW >= sumE) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] arr = {1, 1, 2, 1, 1};
        Solution335 solution335 = new Solution335();
        System.out.println(solution335.isSelfCrossing(arr));
    }

}
